package org.sparkle.ioc;

import java.util.List;
import java.util.Map;

import org.sparkle.register.AbstractRegister;
import org.sparkle.register.Register;
import org.sparkle.register.RegisterObj;
import org.sparkle.scanner.AnnotationScanner;

@Register(name="IocRegister")
public class IocRegister extends AbstractRegister{

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public void populateInstances(AnnotationScanner scanner,
			Map<String, RegisterObj> map) {
		List<Class> annotatedClasses= scanner.getListByAnnotation(Bean.class);		
		for(Class c: annotatedClasses){				
			Bean ann=(Bean) c.getAnnotation(Bean.class);			
			map.put(ann.value(),new RegisterObj(c,null,ann.singleton(),ann.init_method(),ann.lazy()));				
		}
		
		RegisterObj robj=null;
		
		for(String id: map.keySet()){			
			robj=map.get(id);			
			if(!robj.isLazy()){				
				ServiceLookup.getInstance().get(id);				
			}			
		}		
	}

}
